#ifndef INPUT_H
#define INPUT_H

#include <windows.h>
#include "types.h"

class WINAPP;
class ID_KEYBOARD;
class ID_MOUSE;

//---------------------------------------------------------
#define CT_CURRENT		(0)
#define CT_HELD			(1)
#define CT_PRESSED		(2)
#define CT_RELEASED		(3)
#define CT_LAST			(4)

#define CT_MAX			(5)

//---------------------------------------------------------
//	input defines
//---------------------------------------------------------
#define	INPUT_UP		(1<<0)
#define	INPUT_DOWN		(1<<1)
#define	INPUT_LEFT		(1<<2)
#define	INPUT_RIGHT		(1<<3)
#define	INPUT_BUTTON0	(1<<4)
#define	INPUT_BUTTON1	(1<<5)
#define	INPUT_BUTTON2	(1<<6)
#define	INPUT_BUTTON3	(1<<7)
#define	INPUT_BUTTON4	(1<<8)
#define	INPUT_BUTTON5	(1<<9)
#define	INPUT_BUTTON6	(1<<10)
#define	INPUT_BUTTON7	(1<<11)
#define	INPUT_BUTTON8	(1<<12)
#define	INPUT_BUTTON9	(1<<13)
#define	INPUT_BUTTON10	(1<<14)
#define	INPUT_BUTTON11	(1<<15)
#define	INPUT_BUTTON12	(1<<16)
#define	INPUT_BUTTON13	(1<<17)
#define	INPUT_BUTTON14	(1<<18)
#define	INPUT_BUTTON15	(1<<19)
#define	INPUT_BUTTON16	(1<<20)
#define	INPUT_BUTTON17	(1<<21)
#define	INPUT_BUTTON18	(1<<22)
#define	INPUT_BUTTON19	(1<<23)
#define	INPUT_BUTTON20	(1<<24)
#define	INPUT_BUTTON21	(1<<25)
#define	INPUT_BUTTON22	(1<<26)
#define	INPUT_BUTTON23	(1<<27)
#define	INPUT_BUTTON24	(1<<28)
#define	INPUT_BUTTON25	(1<<29)
#define	INPUT_BUTTON26	(1<<30)
#define	INPUT_BUTTON27	(1<<31)

//---------------------------------------------------------
//	an input device
//---------------------------------------------------------
class INPUTDEVICE
{
	friend class UNILIST;

public:
	INPUTDEVICE( INPUTDEVICE **ppme );
	virtual ~INPUTDEVICE();

	virtual void		Process();
	virtual ID_KEYBOARD *IsKeyboard()		{	return 0;	}
	virtual ID_MOUSE	*IsMouse()			{	return 0;	}

	u32		GetControls( u32 type=CT_CURRENT )
	{	return controls[type];	}


protected:
	INPUTDEVICE	*next;
	INPUTDEVICE	**ppme;

	u32		controls[CT_MAX];
};

//---------------------------------------------------------
//	a keyboard input device
//---------------------------------------------------------
class ID_KEYBOARD : public INPUTDEVICE
{
public:
			ID_KEYBOARD( INPUTDEVICE **ppme ) : INPUTDEVICE(ppme)	{}
	virtual	ID_KEYBOARD		*IsKeyboard()		{	return this;	}
	virtual	void			MapKey( u32 keyDefine, u32 bits=0 ) = 0;
};

//---------------------------------------------------------
//	a mouse input device
//---------------------------------------------------------
class ID_MOUSE : public INPUTDEVICE
{
public:
			ID_MOUSE( INPUTDEVICE **ppme ) : INPUTDEVICE(ppme)	{}
	virtual	ID_MOUSE		*IsMouse()		{	return this;	}
	virtual	void			GetMovement( s32 *pX=0, s32 *pY=0, s32 *pZ=0 ) = 0;
};

//---------------------------------------------------------
//	the input manager class
//---------------------------------------------------------
class INPUTMGR
{
public:
	INPUTMGR();
	~INPUTMGR();

	bool			Init( HWND hWnd );
	void			Uninit();

	void			Process();
	ID_KEYBOARD		*GetKeyboard();
	ID_MOUSE		*GetMouse();

protected:

	INPUTDEVICE		*pDevices;
};

//---------------------------------------------------------
//---------------------------------------------------------

#endif
